package com.bycx.manage.wechat.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bycx.core.exception.BusinessException;
import com.bycx.core.util.BeanUtil;
import com.bycx.core.util.DateUtils;
import com.bycx.core.util.ExcelHelper;
import com.bycx.core.controller.BaseController;
import com.bycx.core.util.Page;
import com.bycx.dingxinlc.model.TCustLoginInfo;
import com.bycx.manage.wechat.dto.TCustLoginInfoDto;
import com.bycx.manage.wechat.service.ITCustLoginInfoService;

@Controller
@RequestMapping(value="/cust/base/info")
public class TCustLoginInfoController extends BaseController {
	@Autowired
	private ITCustLoginInfoService tCustLoginInfoService;

	@RequiresPermissions(value="cust:base:info:index")
	@RequestMapping(value="/index", method=RequestMethod.GET)
	public String index(Page<?> page){
		return "/manage/wechat/custBaseInfo/custBaseInfo.index";
	}

	@ResponseBody
	@RequiresPermissions(value="cust:base:info:list")
	@RequestMapping(value="/list", method=RequestMethod.POST)
	public Page<?> list(Page<?> page) {
		List<TCustLoginInfoDto> list = tCustLoginInfoService.getList(page.getParams());
		page.setList(list);
		return page;
	}

	/**
	 * Excel导出
	 * @param request
	 * @param response
	 * @param tCustBaseInfo
	 */
    @RequiresPermissions(value="cust:base:info:export")
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void export(HttpServletRequest request,HttpServletResponse response, TCustLoginInfo tCustLoginInfo){
    	Map<String, Object> map = BeanUtil.transBean2Map(tCustLoginInfo);
		List<TCustLoginInfoDto> list = tCustLoginInfoService.getList(map);
		if (list == null || list.size() == 0) {
			throw new BusinessException("导出数据不能为空");
		}
		String[] columns={
            "phoneNo","createDate","orderAmt","orderTime","transcation_id"
        };
        String[] columnNames={
            "手机号","注册时间","支付金额(元)","支付时间","交易单号"
            };
        String  excelName = "客户信息_"+ DateUtils.format(new Date(), "yyyyMMddHHmmss");
        try {
        	ExcelHelper.export("", list, excelName, "Sheet1", columns, columnNames, 0, request, response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new BusinessException("导出请款单失败:"+e.getMessage());
        }
	 }
	
}

